﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework;

namespace FrameworkXNA.Scenes
{
    class Animacao : SceneBase
    {
        AnimatedObject animacao, animacao2;

        public override void start()
        {
            animacao = new AnimatedObject(Game1.instance.Content.Load<Texture2D>("spritesheet"));
            animacao.AddAnimation("walkup", animacao.texture.Width / 3, animacao.texture.Height / 4, 3, 10, AnimatedObject.LoopType.InfiniteLoop, 0, 0);
            animacao.AddAnimation("walkright", animacao.texture.Width / 3, animacao.texture.Height / 4, 3, 10, AnimatedObject.LoopType.InfiniteLoop, 0, animacao.texture.Height / 4);
            animacao.AddAnimation("walkdown", animacao.texture.Width / 3, animacao.texture.Height / 4, 3, 10, AnimatedObject.LoopType.InfiniteLoop, 0, animacao.texture.Height / 4 * 2);
            animacao.AddAnimation("walkleft", animacao.texture.Width / 3, animacao.texture.Height / 4, 3, 10, AnimatedObject.LoopType.InfiniteLoop, 0, animacao.texture.Height / 4 * 3);
            animacao.setAnimation("walkup");

            animacao2 = new AnimatedObject(Game1.instance.Content.Load<Texture2D>("spritesheet"));
            animacao2.AddAnimation("walkup", animacao2.texture.Width / 3, animacao2.texture.Height / 4, 3, 10, AnimatedObject.LoopType.InfiniteLoop, 0, 0);
            animacao2.setAnimation("walkup");
            animacao2.x = 300;
            base.start();
        }

        public override void update(Microsoft.Xna.Framework.GameTime gameTime)
        {
           
            #region movements
                if (Controller.keyDown(Keys.Right))
            {
                animacao.x += 5;
                animacao.setAnimation("walkright");
            }

            if (Controller.keyDown(Keys.Down))
            {
                animacao.y += 5;
                animacao.setAnimation("walkdown");
            }

            if (Controller.keyDown(Keys.Up))
            {
                animacao.y -= 5;
                animacao.setAnimation("walkup");
            }

            if (Controller.keyDown(Keys.Left))
            {
                animacao.x -= 5;
                animacao.setAnimation("walkleft");
            }
                #endregion

            if (animacao.Clicked())
            {
                animacao.scaleX += 0.1f;
            }

            animacao.Update();
            animacao2.Update();
            base.update(gameTime);
        }

        public override void draw(SpriteBatch spriteBatch)
        {
            animacao.Draw(spriteBatch);
            animacao2.Draw(spriteBatch);
            base.draw(spriteBatch);
        }
    }
}
